(function (vc) {
    vc.extends({
        propTypes: {
            callBackListener: vc.propTypes.string, //父组件名称
            callBackFunction: vc.propTypes.string //父组件监听方法
        },
        data: {
            addDistributionModeInfo: {
                modeId: '',
                modeName: '',
                fixedFee: '',
                startDeliveryIn: '-1',
                startDeliveryOut: '-1',
                maximumDistribution: '-1',
                shopId: '',
                isShow: ''
            }
        },
        _initMethod: function () {
        },
        _initEvent: function () {
            vc.on('addDistributionMode', 'openAddDistributionModeModal', function () {
                $('#addDistributionModeModel').modal('show');
            });
        },
        methods: {
            addDistributionModeValidate() {
                return vc.validate.validate({
                    addDistributionModeInfo: $that.addDistributionModeInfo
                }, {
                    'addDistributionModeInfo.modeName': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "方式名称不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "30",
                            errInfo: "方式名称不能超过30"
                        },
                    ]
                });
            },
            saveDistributionModeInfo: function () {
                if (!$that.addDistributionModeValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }
                $that.addDistributionModeInfo.shopId = vc.getCurrentCommunity().shopId;
                //不提交数据将数据 回调给侦听处理
                if (vc.notNull($props.callBackListener)) {
                    vc.emit($props.callBackListener, $props.callBackFunction, $that.addDistributionModeInfo);
                    $('#addDistributionModeModel').modal('hide');
                    return;
                }
                vc.http.apiPost(
                    '/distributionMode/saveDistributionMode',
                    JSON.stringify($that.addDistributionModeInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#addDistributionModeModel').modal('hide');
                            $that.clearAddDistributionModeInfo();
                            vc.emit('distributionModeManage', 'listDistributionMode', {});
                            vc.toast("添加成功");
                            return;
                        }
                        vc.toast(_json.msg);
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    });
            },
            clearAddDistributionModeInfo: function () {
                $that.addDistributionModeInfo = {
                    modeId: '',
                    modeName: '',
                    fixedFee: '',
                    startDeliveryIn: '',
                    startDeliveryOut: '',
                    maximumDistribution: '',
                    shopId: ''
                };
            }
        }
    });
})(window.vc);
